package com.zhengshang.web.controller.app;

import java.util.List;

import com.zhengshang.api.domain.AppNavigate;
import com.zhengshang.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.api.domain.AppBanner;
import com.zhengshang.api.service.IAppBannerService;
import com.zhengshang.common.utils.poi.ExcelUtil;
import com.zhengshang.common.core.page.TableDataInfo;

/**
 * APP端banner图Controller
 * 
 * @author zhengshang
 * @date 2021-03-09
 */
@RestController
@RequestMapping("/app/banner")
public class AppBannerController extends BaseController
{
    @Autowired
    private IAppBannerService appBannerService;

    /**
     * 查询APP端banner图列表
     */
    @PreAuthorize("@ss.hasPermi('app:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppBanner appBanner)
    {
        startPage();
        List<AppBanner> list = appBannerService.selectAppBannerList(appBanner);
        return getDataTable(list);
    }

    /**
     * 导出APP端banner图列表
     */
    @PreAuthorize("@ss.hasPermi('app:banner:export')")
    @Log(title = "APP端banner图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppBanner appBanner)
    {
        List<AppBanner> list = appBannerService.selectAppBannerList(appBanner);
        ExcelUtil<AppBanner> util = new ExcelUtil<AppBanner>(AppBanner.class);
        return util.exportExcel(list, "banner");
    }

    /**
     * 获取APP端banner图详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return AjaxResult.success(appBannerService.selectAppBannerById(bannerId));
    }

    /**
     * 新增APP端banner图
     */
    @PreAuthorize("@ss.hasPermi('app:banner:add')")
    @Log(title = "APP端banner图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppBanner appBanner)
    {
        appBanner.setCreateBy(SecurityUtils.getUsername());
        return toAjax(appBannerService.insertAppBanner(appBanner));
    }

    /**
     * 修改APP端banner图
     */
    @PreAuthorize("@ss.hasPermi('app:banner:edit')")
    @Log(title = "APP端banner图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppBanner appBanner)
    {
        return toAjax(appBannerService.updateAppBanner(appBanner));
    }

    /**
     * 删除APP端banner图
     */
    @PreAuthorize("@ss.hasPermi('app:banner:remove')")
    @Log(title = "APP端banner图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(appBannerService.deleteAppBannerByIds(bannerIds));
    }


    /**
     * 状态修改
     */
    @PutMapping("/changeBannerStatus")
    public AjaxResult changeBannerStatus(@RequestBody AppBanner appBanner)
    {
        return toAjax(appBannerService.updateAppBannerStatus(appBanner));
    }
}
